/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CustomerPanel.java
 *
 * Created on 26-10-2011, 20:44:20
 */
package GUILager;
import ModelLager.CustomerP;
import ControlLager.CustomerPCTR;
import java.util.ArrayList;
import javax.swing.JTable;

/**
 *
 * @author Jonas Kristensen
 */
public class CustomerPanel extends javax.swing.JPanel {
private CustomerPCTR customerCTR;
    /** Creates new form SupplierPanel */
    public CustomerPanel() 
    {
        initComponents();
        customerCTR = new CustomerPCTR();
    /** Creates new form CustomerPanel */

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrame1 = new javax.swing.JFrame();
        jFrame2 = new javax.swing.JFrame();
        jFrame3 = new javax.swing.JFrame();
        ListsPanel = new javax.swing.JPanel();
        jLabel1Name = new javax.swing.JLabel();
        jLabel1Address = new javax.swing.JLabel();
        jLabel1ZipCode = new javax.swing.JLabel();
        jLabel1PhoneNo = new javax.swing.JLabel();
        jLabel1Country = new javax.swing.JLabel();
        jLabel1CustomerID = new javax.swing.JLabel();
        jLabel1Discount = new javax.swing.JLabel();
        jLabel1BonusSystem = new javax.swing.JLabel();
        TextFieldName = new javax.swing.JTextField();
        TextFieldAddress = new javax.swing.JTextField();
        TextFieldPostnr = new javax.swing.JTextField();
        TextFieldTelefonnr = new javax.swing.JTextField();
        TextFieldLand = new javax.swing.JTextField();
        TextFieldKundeNr = new javax.swing.JTextField();
        TextFieldRabat = new javax.swing.JTextField();
        TextFieldBonusSystem = new javax.swing.JTextField();
        jButtonFindCustomerByID = new javax.swing.JButton();
        jButtonCreateCustomer = new javax.swing.JButton();
        jButtonUpdateCustomer = new javax.swing.JButton();
        jButtonDeleteCustomer = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableCustomer = new javax.swing.JTable();
        jButtonCleanFields = new javax.swing.JButton();
        jButtonCleanTable = new javax.swing.JButton();
        jLabelStatus = new javax.swing.JLabel();
        jButtonListAllCustomer = new javax.swing.JButton();

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jFrame2Layout = new javax.swing.GroupLayout(jFrame2.getContentPane());
        jFrame2.getContentPane().setLayout(jFrame2Layout);
        jFrame2Layout.setHorizontalGroup(
            jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame2Layout.setVerticalGroup(
            jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jFrame3Layout = new javax.swing.GroupLayout(jFrame3.getContentPane());
        jFrame3.getContentPane().setLayout(jFrame3Layout);
        jFrame3Layout.setHorizontalGroup(
            jFrame3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame3Layout.setVerticalGroup(
            jFrame3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setBorder(javax.swing.BorderFactory.createEtchedBorder());

        ListsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Informationer af Customer"));

        jLabel1Name.setText("Navn:");

        jLabel1Address.setText("Adresse:");

        jLabel1ZipCode.setText("Post nr:");

        jLabel1PhoneNo.setText("Telefon nr:");

        jLabel1Country.setText("Land:");

        jLabel1CustomerID.setText("Kunde nr:");

        jLabel1Discount.setText("Rabat:");

        jLabel1BonusSystem.setText("Bonus system:");

        TextFieldTelefonnr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextFieldTelefonnrActionPerformed(evt);
            }
        });

        TextFieldLand.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextFieldLandActionPerformed(evt);
            }
        });

        TextFieldKundeNr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextFieldKundeNrActionPerformed(evt);
            }
        });

        TextFieldRabat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextFieldRabatActionPerformed(evt);
            }
        });

        TextFieldBonusSystem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextFieldBonusSystemActionPerformed(evt);
            }
        });

        jButtonFindCustomerByID.setText("Søg på kunde ID");
        jButtonFindCustomerByID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFindCustomerByIDActionPerformed(evt);
            }
        });

        jButtonCreateCustomer.setText("Opret en kunde");
        jButtonCreateCustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreateCustomerActionPerformed(evt);
            }
        });

        jButtonUpdateCustomer.setText("Ændre på en kunde");
        jButtonUpdateCustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonUpdateCustomerActionPerformed(evt);
            }
        });

        jButtonDeleteCustomer.setText("Slet en kunde");
        jButtonDeleteCustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDeleteCustomerActionPerformed(evt);
            }
        });

        jTableCustomer.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Navn", "Adresse", "Post nr.", "Telefon nr.", "Land", "Kunde ID", "Rabat", "Bonus System"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Double.class, java.lang.Double.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTableCustomer);

        jButtonCleanFields.setText("Ryd alle felter");
        jButtonCleanFields.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCleanFieldsActionPerformed(evt);
            }
        });

        jButtonCleanTable.setText("Ryd tabel");
        jButtonCleanTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCleanTableActionPerformed(evt);
            }
        });

        jButtonListAllCustomer.setText("Alle kunder");
        jButtonListAllCustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonListAllCustomerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ListsPanelLayout = new javax.swing.GroupLayout(ListsPanel);
        ListsPanel.setLayout(ListsPanelLayout);
        ListsPanelLayout.setHorizontalGroup(
            ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ListsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(ListsPanelLayout.createSequentialGroup()
                            .addComponent(jLabel1PhoneNo)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1Country)
                            .addComponent(jLabel1CustomerID)
                            .addComponent(jLabel1Discount)
                            .addComponent(jLabel1BonusSystem)))
                    .addComponent(jLabel1ZipCode)
                    .addComponent(jLabel1Address)
                    .addComponent(jLabel1Name))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(TextFieldBonusSystem)
                    .addComponent(TextFieldRabat)
                    .addComponent(TextFieldKundeNr)
                    .addComponent(TextFieldLand)
                    .addComponent(TextFieldTelefonnr)
                    .addComponent(TextFieldPostnr)
                    .addComponent(TextFieldName)
                    .addComponent(TextFieldAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ListsPanelLayout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addComponent(jLabelStatus))
                    .addGroup(ListsPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonFindCustomerByID))
                    .addGroup(ListsPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonCreateCustomer)
                            .addComponent(jButtonUpdateCustomer)
                            .addComponent(jButtonDeleteCustomer)
                            .addComponent(jButtonCleanFields))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ListsPanelLayout.createSequentialGroup()
                        .addComponent(jButtonListAllCustomer)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCleanTable))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 754, Short.MAX_VALUE))
                .addContainerGap())
        );
        ListsPanelLayout.setVerticalGroup(
            ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ListsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ListsPanelLayout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1Name)
                            .addComponent(TextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonFindCustomerByID)
                            .addComponent(jButtonListAllCustomer)
                            .addComponent(jButtonCleanTable))
                        .addGap(18, 18, 18)
                        .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(ListsPanelLayout.createSequentialGroup()
                                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1Address)
                                    .addComponent(TextFieldAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButtonCreateCustomer))
                                .addGap(18, 18, 18)
                                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1ZipCode)
                                    .addComponent(TextFieldPostnr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButtonUpdateCustomer))
                                .addGap(18, 18, 18)
                                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1PhoneNo)
                                    .addComponent(TextFieldTelefonnr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButtonDeleteCustomer))
                                .addGap(18, 18, 18)
                                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1Country)
                                    .addComponent(TextFieldLand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButtonCleanFields))
                                .addGap(18, 18, 18)
                                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1CustomerID)
                                    .addComponent(TextFieldKundeNr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1Discount)
                                    .addComponent(TextFieldRabat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(ListsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1BonusSystem)
                                    .addComponent(TextFieldBonusSystem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(ListsPanelLayout.createSequentialGroup()
                        .addGap(248, 248, 248)
                        .addComponent(jLabelStatus)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel1Name.getAccessibleContext().setAccessibleName("Name:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ListsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ListsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        ListsPanel.getAccessibleContext().setAccessibleName("Info af Customer");
    }// </editor-fold>//GEN-END:initComponents
    private void clearFields()
    {
        TextFieldName.setText("");
        TextFieldAddress.setText("");
        TextFieldPostnr.setText("");
        TextFieldTelefonnr.setText("");
        TextFieldLand.setText("");
        TextFieldKundeNr.setText("");
        TextFieldRabat.setText("");
        TextFieldBonusSystem.setText("");

    }
    
    private void putValuesOnScreen(CustomerP cObj)
    {
        TextFieldName.setText(cObj.getName());
        TextFieldAddress.setText(cObj.getAddress());
        TextFieldPostnr.setText(cObj.getZipCode());
        TextFieldTelefonnr.setText(cObj.getPhoneNo());
        TextFieldLand.setText(cObj.getCountry());
        TextFieldKundeNr.setText("" + cObj.getCustomerID());
        TextFieldRabat.setText("" +cObj.getDiscount());
        TextFieldBonusSystem.setText("" + cObj.getBonusSystem());
    }
    
    private void clearTable(JTable table)
    {
        int rowCount = 0;
        while(rowCount < table.getRowCount())
        {
            clearColumn(table, rowCount);
            rowCount++;
        }
    }
    
    private void clearColumn(JTable table, int row)
    {
        int column = 0;
        int size = table.getColumnCount();
        while(column < size)
        {
            table.setValueAt(null, row, column);
            column++;
        }
    } 
    private void TextFieldTelefonnrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextFieldTelefonnrActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TextFieldTelefonnrActionPerformed

    private void TextFieldLandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextFieldLandActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TextFieldLandActionPerformed

    private void TextFieldKundeNrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextFieldKundeNrActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TextFieldKundeNrActionPerformed

    private void TextFieldRabatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextFieldRabatActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TextFieldRabatActionPerformed

    private void TextFieldBonusSystemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextFieldBonusSystemActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TextFieldBonusSystemActionPerformed

    private void jButtonFindCustomerByIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFindCustomerByIDActionPerformed
        try
        {
            
            if(TextFieldKundeNr.getText().length() == 0)
            {
               jLabelStatus.setText("Indtast ID!");
            }
            else
            {
                int input = Integer.parseInt(TextFieldKundeNr.getText().trim());
                CustomerP cObj = customerCTR.findCustomerP(input);
                if(cObj == null)
                {
                    jLabelStatus.setText("denne kunde ID eksisterer ikke");
                }
                else
                {
                    clearFields();
                    putValuesOnScreen(cObj);
                }
            }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
            jLabelStatus.setText("Indtast gyldigt id");
        }
    }//GEN-LAST:event_jButtonFindCustomerByIDActionPerformed

    private void jButtonCleanTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCleanTableActionPerformed
      clearTable(jTableCustomer);
        
    }//GEN-LAST:event_jButtonCleanTableActionPerformed

    private void jButtonCleanFieldsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCleanFieldsActionPerformed
        clearFields();
    }//GEN-LAST:event_jButtonCleanFieldsActionPerformed

    private void jButtonCreateCustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCreateCustomerActionPerformed
        try
        {
            if(TextFieldName.getText().length() == 0 || TextFieldAddress.getText().length() == 0 || TextFieldPostnr.getText().length() == 0 || TextFieldTelefonnr.getText().length() == 0 || TextFieldLand.getText().length() == 0 || TextFieldKundeNr.getText().length() == 0 || TextFieldRabat.getText().length() == 0|| TextFieldBonusSystem.getText().length() == 0)
            {
                jLabelStatus.setText("UDFYLD alle felter");
            }
            else
            {
                String name = TextFieldName.getText();
                String address = TextFieldAddress.getText();
                String zipcode = TextFieldPostnr.getText();
                String phoneNo = TextFieldTelefonnr.getText();
                
                String country = TextFieldLand.getText();
                int customerID = Integer.parseInt(TextFieldKundeNr.getText());
                double discount =Double.parseDouble(TextFieldRabat.getText());
                double bonusSystem =Double.parseDouble(TextFieldBonusSystem.getText());
                
                customerCTR.createCustomer(name, address, zipcode, phoneNo, country, customerID, discount, bonusSystem);
                jLabelStatus.setText("Customer er nu oprettet!");
            }       
        }
        catch(NumberFormatException e)
        {
            jLabelStatus.setText("Indtast gyldig værdi som ID!");
            System.out.println(e.getMessage());
        }
        
        catch(Exception e)
        {
            jLabelStatus.setText("Der er en fejl i dine informationer");
            System.out.println(e.getMessage());
        }
    }//GEN-LAST:event_jButtonCreateCustomerActionPerformed

    private void jButtonUpdateCustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUpdateCustomerActionPerformed
        try
          {
            String name = TextFieldName.getText();
            String address = TextFieldAddress.getText();
            String zipCode = TextFieldPostnr.getText();
            String phoneNo = TextFieldTelefonnr.getText();

            String country = TextFieldLand.getText();
            int customerID = Integer.parseInt(TextFieldKundeNr.getText());
            double discount = Double.parseDouble(TextFieldRabat.getText());
            double bonusSystem = Double.parseDouble(TextFieldBonusSystem.getText());
            
            customerCTR.updateCustomerP(name, address, zipCode, phoneNo, country, customerID, discount,bonusSystem);
            jLabelStatus.setText("Supplier opdateret");
          }
      
          catch(Exception e)
          {
              System.out.println(e.getMessage());
              
          }
          
    
    }//GEN-LAST:event_jButtonUpdateCustomerActionPerformed

    private void jButtonDeleteCustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteCustomerActionPerformed
        
        try
        {
            int customerID =Integer.parseInt(TextFieldKundeNr.getText());
            if(customerCTR.deleteCustomerP(customerID) == 1)
            {
                jLabelStatus.setText("Slettet");
            }
            else
            {
                jLabelStatus.setText("Kunden blev ikke fundet");
            }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
            jLabelStatus.setText("Du skal indtaste den rigtige ID");
        }
    }//GEN-LAST:event_jButtonDeleteCustomerActionPerformed

    private void jButtonListAllCustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonListAllCustomerActionPerformed
        clearTable(jTableCustomer);
        ArrayList<CustomerP> customer = customerCTR.getAllCustomer();
        int row = 0;
        for(CustomerP cust : customer)
        {
            jTableCustomer.setValueAt(cust.getName(), row, 0);
            jTableCustomer.setValueAt(cust.getAddress(), row, 1);
            jTableCustomer.setValueAt(cust.getZipCode(), row, 2);
            jTableCustomer.setValueAt(cust.getPhoneNo(), row, 3);
            jTableCustomer.setValueAt(cust.getCountry(), row, 4);
            jTableCustomer.setValueAt(cust.getCustomerID(), row, 5);
            jTableCustomer.setValueAt(cust.getDiscount(), row, 6);
            jTableCustomer.setValueAt(cust.getBonusSystem(), row, 7);
            row++;
        }
    }//GEN-LAST:event_jButtonListAllCustomerActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ListsPanel;
    private javax.swing.JTextField TextFieldAddress;
    private javax.swing.JTextField TextFieldBonusSystem;
    private javax.swing.JTextField TextFieldKundeNr;
    private javax.swing.JTextField TextFieldLand;
    private javax.swing.JTextField TextFieldName;
    private javax.swing.JTextField TextFieldPostnr;
    private javax.swing.JTextField TextFieldRabat;
    private javax.swing.JTextField TextFieldTelefonnr;
    private javax.swing.JButton jButtonCleanFields;
    private javax.swing.JButton jButtonCleanTable;
    private javax.swing.JButton jButtonCreateCustomer;
    private javax.swing.JButton jButtonDeleteCustomer;
    private javax.swing.JButton jButtonFindCustomerByID;
    private javax.swing.JButton jButtonListAllCustomer;
    private javax.swing.JButton jButtonUpdateCustomer;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JFrame jFrame2;
    private javax.swing.JFrame jFrame3;
    private javax.swing.JLabel jLabel1Address;
    private javax.swing.JLabel jLabel1BonusSystem;
    private javax.swing.JLabel jLabel1Country;
    private javax.swing.JLabel jLabel1CustomerID;
    private javax.swing.JLabel jLabel1Discount;
    private javax.swing.JLabel jLabel1Name;
    private javax.swing.JLabel jLabel1PhoneNo;
    private javax.swing.JLabel jLabel1ZipCode;
    private javax.swing.JLabel jLabelStatus;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableCustomer;
    // End of variables declaration//GEN-END:variables
}

